# coding:   utf-8
# 作者(@Author):   Messimeimei
# 创建时间(@Created_time): 2023/1/4 20:00
 
"""登录需要的数据库模型（用户表）"""
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from app import db
 
 
class User(UserMixin, db.Model):
    # 第一个参数指定字段类型，后面设置属性
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    count = db.Column(db.String(128), nullable=False)
    password = db.Column(db.String(128), nullable=False)
 
    def __init__(self, count, password):
        self.count = count
        self.password = password
 
    def set_password(self, password):
        self.password = generate_password_hash(password)
 
    def check_password(self, password):
        return check_password_hash(self.password, password)
 
 
if __name__ == '__main__':
    user = User(count='0101', password=2021)
    db.session.add(user)
    db.session.commit()